package com.scy.java.io.output;


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

//字节数组输出流
public class FileOutputStreamWrites {
    public static void main(String[] args) {
        FileOutputStream fos=null;
        try {
            fos = new FileOutputStream("fos.txt");
            //定义文件的内容
            String str = "good good study day day up";
            //字符串转化位字节数组
            byte[] bytes = str.getBytes();
            //写出字节数组数据从下标0开始写出字符串长度的字节数
            fos.write(bytes,0,str.length());
            System.out.println("写入完毕");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //关流
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

        }

    }
}
